package com.tz.system.menu.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.tz.platform.page.PageCondition;
import com.tz.platform.utils.StringUtil;
import com.tz.system.menu.model.TSysMenu;
import com.tz.system.menu.service.TSysMenuService;

@Controller
@RequestMapping("/system/menu/tSysMenu")
public class TSysMenuController {

	@Autowired
	private TSysMenuService tSysMenuService;

	/**
	 * 跳转到列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/list")
	@ResponseBody
	public ModelAndView list(PageCondition pl, Model model) {
		// 设置页面属性
		model.addAllAttributes(pl.getParamsCondition());
		// 2、执行查询
		pl.setSortBys("menuCode", "asc");
		pl = tSysMenuService.findByPage(pl);
		// 3、设置查询结果
		model.addAttribute("pl", pl);
		return new ModelAndView("/system/menu/t-sys-menu-list");
	}

	/**
	 * 查询列表页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/toAddPage")
	public ModelAndView toAddPage(Model model, String id) {
		if (!StringUtil.msIsEmpty(id)) {
			TSysMenu entity = tSysMenuService.queryById(Integer.parseInt(id));
			model.addAttribute("entity", entity);
		}
		return new ModelAndView("/system/menu/t-sys-menu-form");
	}

	/**
	 * 增加信息
	 * @param model
	 * @param entity
	 * @return
	 */
	@RequestMapping(value = "/addSave")
	@ResponseBody
	public Map<String, Object> addSave(TSysMenu entity) {
		return tSysMenuService.addSave(entity);
	}

	/**
	 * 更新信息
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "/updateSave")
	@ResponseBody
	public Map<String, Object> updateSave(TSysMenu entity) {
		return tSysMenuService.updateSave(entity);
	}

	/**
	 * 根据id删除信息
	 * @param model
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/deleteObj")
	@ResponseBody
	public Map<String, Object> deleteObj(String id) {
		return tSysMenuService.removeById(Integer.valueOf(id));
	}

}
